< previous page page_144 next page >

Page 144
Table 7.2 Set the buttons Argument to One of the Following Values to Specify Which Set of Buttons to Use
Button SetValueConstant
OK0vbOKOnly
OK, Cancel1vbOKCancel
Abort, Retry, Ignore2VBAbortRetryIgnore
Yes, No, Cancel3vbYesNoCancel
Yes, No4vbYesNo
Retry, Cancel5vbRetryCancel

Because the buttons argument controls both the icon and the command button(s) used for a message box, you might wonder how you can specify both at the same time. You do so by adding the values of the constants together. The MsgBox function is designed so that any combination of the icon constant and the command button constant creates a unique value. This value is then broken down by the function, to specify the individual pieces. The following code combines an icon constant and command button constant to create a warning message that allows the user to choose an action. The results of the code are illustrated in Figure 7.3:
nOptVal = vbExclamation + vbAbortRetryIgnore
nRetVal = MsgBox("File does not exist.", nOptVal, "My Application")
note.gif If you want your message box to display a Help button, add the constant vbMsgBoxHelpButton, which has a value of 16384, to whichever button set constant you choose. square.gif

0144-01.jpg
Figure 7.3
The 
buttons argument controls
both the icon and the command
buttons displayed by the 
MsgBox function.
Setting the Default Button
If you are using more than one command button in the message box, you can also specify which button is the default. The default button is the one that has focus when the message box is displayed. This button is the one that the user is most likely to choose so that he or she can just press the Enter key. For example, if you display a message box to have the user confirm the deletion of the record, you probably should set up the default button so that the record would not be deleted. This way, the user must make a conscious choice to delete the record.

 
< previous page page_144 next page >